<?php

declare(strict_types=1);

namespace Modules\Inventory\Models;

use Illuminate\Database\Eloquent\Relations\HasMany;
use Modules\Base\Models\Material;
use Modules\Warehouse\Models\Stash;
use Modules\Warehouse\Models\Storagelocation;
use Catch\Base\CatchModel as Model;

/**
 * @property $id
 * @property $order_id
 * @property $material_no
 * @property $from_location
 * @property $from_lotnum
 * @property $to_location
 * @property $to_lotnum
 * @property $qty
 * @property $from_wms
 * @property $to_wms
 * @property $unit
 * @property $creator_id
 * @property $created_at
 * @property $updated_at
 * @property $deleted_at
*/
class TransferOrderDetail extends Model
{


    protected $table = 'transfer_order_detail';

    protected $fillable = [ 'id', 'order_id','supplier_code', 'material_no', 'from_location', 'from_lotnum', 'to_location', 'to_lotnum', 'qty', 'from_wms', 'to_wms', 'unit', 'creator_id', 'created_at', 'updated_at', 'deleted_at' ];

    /**
     * @var array
     */
    protected array $fields = ['id','order_id','supplier_code','material_no','from_location','from_lotnum','to_location','to_lotnum','qty','from_wms','to_wms','unit','created_at','updated_at'];

    /**
     * @var array
     */
    protected array $form = ['id','order_id','supplier_code','material_no','from_location','from_lotnum','to_location','to_lotnum','qty','from_wms','to_wms','unit','created_at','updated_at'];

    /**
     * @var array
     */
    public array $searchable = [
        'order_id' => '=',
        'material_no' => '=',

    ];

    /**
     * 时间格式化
     * @param $date
     * @return mixed
     */
    protected function serializeDate($date)
    {
        return $date->format('Y-m-d H:i');
    }

    /**
     * 关联生产入库头信息
     * @return mixed
     */
    public function order(){
        return $this->belongsTo(TransferOrder::class,'order_id');
    }

    /**
     * 返回产品信息
     * @return HasMany
     */
    public function material()
    {
        return $this->hasOne(Material::class,'fnumber','material_no');
    }

    /**
     * 关联库位信息
     * @return mixed
     */
    public function f_location(){
        return $this->hasOne(Storagelocation::class,'warehousecode','from_location');
    }

    /**
     * 关联仓库信息
     * @return mixed
     */
    public function f_wms(){
        return $this->hasOne(Stash::class,'fnumber','from_wms');
    }


}
